package com.team6.cet.controller;

import static org.hamcrest.CoreMatchers.nullValue;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.validation.Valid;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.team6.cet.entity.ExaminationInformation;
import com.team6.cet.entity.IStatusMessage;
import com.team6.cet.entity.ResponseResult;
import com.team6.cet.service.ExaminationInformationService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@CrossOrigin(origins = "*")
@RestController
@EnableAutoConfiguration
@Api(tags = "考试信息api")
@Validated
/**
 * 考试信息控制类*/
public class ExaminationInformationController {
	@Autowired  
	private ExaminationInformationService examService;
	/**
	 * 查看考试信息*/
	@ApiOperation(value = "查看考试信息") 
	@GetMapping("/findallexam")
	public Object exam()
	{
		Map map=new HashMap();
		List<ExaminationInformation> exams =examService.findExam();
		map.put("code", 0);
		map.put("data", exams);
		map.put("count",10);
		return  map;
	}
	
	@GetMapping("/examlist")
	public ResponseResult examlist()
	{
	 
		List<ExaminationInformation> exams =examService.findExam();
		 
	
		ResponseResult responseResult = new ResponseResult();
		responseResult.setCode(IStatusMessage.SystemStatus.ERROR.getCode());
		responseResult.setCode(IStatusMessage.SystemStatus.SUCCESS.getCode());
		responseResult.setMessage("添加成功");
		responseResult.setObj(exams);
		return responseResult;
	 
	}
	 
	
	/**
	 * 根据id删除考试信息*/
	@ApiOperation(value = "根据id删除考试信息")  
	@GetMapping("/delexam")
	public Object delexam(@RequestParam(value = "Id", required = false) Integer id)
	{
		Map map=new HashMap();
		examService.delExam(id);
		List<ExaminationInformation> exams =examService.findExam();
		map.put("exams", exams);
		return  map;
	}
	/**
	 * 添加考试信息*/
	@ApiOperation(value = "添加考试信息")  
	@PostMapping("/addexam") 
	public ResponseResult addexam(@ApiParam(required = true, value = "添加考试信息")@RequestBody @Valid ExaminationInformation exam )
	{
		examService.InsertExam(exam );
		ResponseResult responseResult = new ResponseResult();
		responseResult.setCode(IStatusMessage.SystemStatus.ERROR.getCode());
		responseResult.setCode(IStatusMessage.SystemStatus.SUCCESS.getCode());
		responseResult.setMessage("添加成功");
		return responseResult;
	}
	/**
	 * 根据id查询考试信息*/
	@ApiOperation(value = "根据id查询考试信息")  
	@GetMapping("/getexamid")
	public ResponseResult getexam(@RequestParam(value = "Id", required = false) Integer id)
	{
		ResponseResult responseResult = new ResponseResult();
		responseResult.setCode(IStatusMessage.SystemStatus.ERROR.getCode());
		responseResult.setCode(IStatusMessage.SystemStatus.SUCCESS.getCode());
		ExaminationInformation exam;
		exam=examService.findExamById(id);
		responseResult.setObj(exam);
		return  responseResult;
	}
	/**
	 * 更新考试信息*/
	@ApiOperation(value = "更新考试信息")  
	@PostMapping("/updateexam")
	public ResponseResult update(@ApiParam(required = true, value = "更新考试信息")@RequestBody @Valid ExaminationInformation exam )
	{
		examService.UpdataExam(exam);
		ResponseResult responseResult = new ResponseResult();
		responseResult.setCode(IStatusMessage.SystemStatus.ERROR.getCode());
		responseResult.setCode(IStatusMessage.SystemStatus.SUCCESS.getCode());
		responseResult.setMessage("修改成功");
		return responseResult;
	}
}
